// pages/asc/apple/appleType/appleType.js
var _utils = require('../../../../utils/utils.js')
var _http = require('../../../../utils/httpUtils.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        program: "",
        programType: "",
        cate_id:'', // 选择的项目id
        teacher: null,
        teacherId: null,
        eStatus: 1,
        kcId:"",
        prePage:false, // 是否是从上个页面来的
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        // getStatusPro(this);\
        // let p = "";
        // let t = "";

        // // if(getApp().other){
        // p = getApp().other.p;
        // t = getApp().other.t;

        // console.log(t, p);
        // this.setData({
        //     program: p,
        //     teacher: t
        // })
        // getApp().other = {};
        // }


    },
    chooseProgram: function () {
        let stat = this.data.eStatus;
        // if (stat == 0) {
        //     _utils.toast('项目正在申请中');
        //     return;
        // } else if (stat == 1) {
        //     _utils.toast('项目正在进行中');
        //     return;
        // }

        if(this.data.kcId){
            return;
        }

        wx.navigateTo({
            url: '../appleTypeProgram/appleTypeProgram',
            success: function (res) { },
            fail: function (res) { },
            complete: function (res) { },
        })
    },
    chooseTeacher: function () {
        console.log(1122);
        if(this.data.kcId){
            return;
        }

        wx.navigateTo({
            url: '../../faculty_choose/faculty_choose?choose=true',
            success: function (res) { },
            fail: function (res) { },
            complete: function (res) { console.log(res); },
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },
    nextPage: function () {
        if (!this.data.program) {
            _utils.toast("请选择项目");
            return;
        }

        if (!this.data.teacher) {
            _utils.toast("请选择教授");
            return;
        }
        let  par = '?program=' + this.data.program + "&t=" + this.data.teacher+"&kcId="+this.data.kcId +"&cate_id="+this.data.cate_id;
        if (this.data.programType == 1) {
            wx.navigateTo({
                url: '../applySummer/applySummer'+par,
                success: function (res) { },
                fail: function (res) { },
                complete: function (res) { },
            })
        } else {
            wx.navigateTo({
                url: '../applyOnline/applyOnline'+par,
                success: function (res) { },
                fail: function (res) { },
                complete: function (res) { },

            })
        }

    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function (options) {

        let p = "";
        let t = "";
        let tid= "";
        console.log(getApp().other);
        if (getApp().other) {
            p = getApp().other.p;
            t = getApp().other.t;
            tid = getApp().other.tid;
            var cateId = getApp().other.cate_id;
            console.log(t, p);
            if (t && p) {
                this.setData({
                    program: p ? p : '',
                    teacher: t ? t : '',
                    kcId:tid,
                    cate_id:cateId,
                    programType:(cateId==1||cateId == 2 )?'2':'1'

                })
            }else{
                if(!this.data.prePage){
                    this.setData({
                        program: '',
                        teacher: '',
                        kcId:'',
                        cate_id:'',
                        programType:'',
                    })
                }else{
                    this.setData({
                        prePage:false
                    })
                }
            }
            getApp().other = {};
        }else{
            if(!this.data.prePage){
                this.setData({
                    program: '',
                    teacher: '',
                    kcId:'',
                    cate_id:'',
                    programType:'',
                })
            }else{
                this.setData({
                    prePage:false
                })
            }
        }


        this.setData({
            eStatus: wx.getStorageSync('eStatus')
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})

function getStatusPro(_this) {
    _http.post(_http.enrollStatus, {}, function () { })
}